/*
 * FaceCat图形通讯框架
 * 著作权编号:2015SR229355+2020SR0266727
 * 上海卷卷猫信息技术有限公司
 */

using System;
using System.Collections.Generic;
using System.Text;

namespace FaceCat {
    /// <summary>
    /// 窗体视图边界
    /// </summary>
    public class FCWindowFrame : FCView {
        /// <summary>
        /// 创建窗体视图
        /// </summary>
        public FCWindowFrame() {
            setBackColor(FCColor.None);
            setBorderColor(FCColor.None);
            setDock(FCDockStyle.Fill);
        }

        /// <summary>
        /// 是否包含坐标
        /// </summary>
        /// <param name="point">坐标</param>
        /// <returns>是否包含</returns>
        public override bool containsPoint(FCPoint point) {
            ArrayList<FCView> views = m_views;
            int viewsSize = views.size();
            for (int i = 0; i < viewsSize; i++) {
                FCWindow window = views.get(i) as FCWindow;
                if (window != null && window.getFrame() == this) {
                    if (window.isDialog()) {
                        return true;
                    }
                    else {
                        return window.containsPoint(point);
                    }
                }
            }
            return false;
        }

        /// <summary>
        /// 获取视图类型
        /// </summary>
        /// <returns>视图类型</returns>
        public override String getViewType() {
            return "WindowFrame";
        }

        /// <summary>
        /// 重绘方法
        /// </summary>
        public override void invalidate() {
            if (m_native != null) {
                ArrayList<FCView> views = m_views;
                int viewsSize = views.size();
                for (int i = 0; i < viewsSize; i++) {
                    FCWindow window = views.get(i) as FCWindow;
                    if (window != null) {
                        m_native.invalidate(window.getDynamicPaintRect());
                        break;
                    }
                }
            }
        }

        /// <summary>
        /// 绘制背景方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public override void onPaintBackground(FCPaint paint, FCRect clipRect) {
            base.onPaintBackground(paint, clipRect);
            if (paint.supportTransparent()) {
                ArrayList<FCView> views = m_views;
                int viewsSize = views.size();
                for (int i = 0; i < viewsSize; i++) {
                    FCWindow window = views.get(i) as FCWindow;
                    if (window != null) {
                        long shadowColor = window.getShadowColor();
                        int shadowSize = window.getShadowSize();
                        if (shadowColor != FCColor.None && shadowSize > 0 && window.isDialog() && window.getFrame() == this) {
                            FCRect bounds = window.getBounds();
                            FCRect leftShadow = new FCRect(bounds.left - shadowSize, bounds.top - shadowSize, bounds.left, bounds.bottom + shadowSize);
                            paint.fillRect(shadowColor, leftShadow);
                            FCRect rightShadow = new FCRect(bounds.right, bounds.top - shadowSize, bounds.right + shadowSize, bounds.bottom + shadowSize);
                            paint.fillRect(shadowColor, rightShadow);
                            FCRect topShadow = new FCRect(bounds.left, bounds.top - shadowSize, bounds.right, bounds.top);
                            paint.fillRect(shadowColor, topShadow);
                            FCRect bottomShadow = new FCRect(bounds.left, bounds.bottom, bounds.right, bounds.bottom + shadowSize);
                            paint.fillRect(shadowColor, bottomShadow);
                            break;
                        }
                    }
                }
            }
        }
    }
}
